package com.seeTools.next.controller.sys;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.seeTools.next.api.entity.sys.SysNotice;
import com.seeTools.next.common.annotation.Log;
import com.seeTools.next.common.core.PageQuery;
import com.seeTools.next.common.core.Result;
import com.seeTools.next.common.enums.BusinessType;
import com.seeTools.next.service.sys.SysNoticeService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * @author seeTools
 * @since 2024-05-19
 */
@Validated
@RestController
@RequestMapping("/sys/notice")
public class SysNoticeController {

    @Resource
    private SysNoticeService sysNoticeService;

    /**
     * 分页查询
     *
     * @param pageQuery
     * @return
     */
    @PostMapping("/list")
    public Result<Page<SysNotice>> findList(@RequestBody PageQuery<SysNotice> pageQuery) {
        Page<SysNotice> pageInfo = sysNoticeService.findList(pageQuery);
        return Result.success(pageInfo);

    }

    /**
     * 修改
     *
     * @return
     */
    @Log(title = "通知公告", businessType = BusinessType.UPDATE)
    @PutMapping()
    public Result<Void> edit(@RequestBody SysNotice sysNotice) {
        return Result.state(sysNoticeService.updateOnLock(sysNotice));
    }

    /**
     * 删除
     *
     * @return
     */
    @Log(title = "通知公告", businessType = BusinessType.DELETE)
    @DeleteMapping()
    public Result<Void> remove(@RequestBody SysNotice sysNotice) {
        return Result.state(sysNoticeService.removeById(sysNotice));
    }

    /**
     * 添加
     *
     * @return
     */
    @Log(title = "通知公告", businessType = BusinessType.INSERT)
    @PostMapping()
    public Result<Void> add(@RequestBody SysNotice sysNotice) {
        return Result.state(sysNoticeService.save(sysNotice));
    }


    /**
     * 获取详情
     *
     * @return
     */
    @GetMapping("/{id}")
    public Result<SysNotice> getInfo(@PathVariable("id") Long id) {
        return Result.state(sysNoticeService.getById(id));
    }

    /**
     * 查询全部
     *
     * @return
     */
    @PostMapping("/all")
    public Result<List<SysNotice>> findAll() {
        return Result.state(sysNoticeService.findAll());
    }


    /**
     * 导出
     *
     * @param response
     */
    @Log(title = "通知公告", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void excel(HttpServletResponse response, @RequestBody SysNotice sysNotice) {
        List<SysNotice> list = sysNoticeService.selectDataList(sysNotice);
    }
}
